package dao;

import utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 李夏
 * @version 1.0
 */
public class ExchangeInfoMapper {
    public static Integer getExchangeOneBuild(Integer buildId) throws SQLException {
        Connection connection = DBUtil.getConnection();
        ResultSet resultSet = null;
        PreparedStatement preparedStatement = null;
        String sql = "select count(*) as exchange_info_count  \n"+
                "from exchange  \n"+
                "where delete_flag=0 and build_id=?";
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, buildId);
        resultSet = preparedStatement.executeQuery();
        Integer count = null;
        if (resultSet.next()) {
            count = resultSet.getInt("exchange_info_count");
        }

        DBUtil.close(connection,preparedStatement,resultSet);


        return count;
    }

    public static Integer queryExchangeAllCount(Integer buildId) throws SQLException {
        Connection connection = DBUtil.getConnection();
        ResultSet resultSet = null;
        PreparedStatement preparedStatement = null;
        String sql = "select count(*) as exchange_all_count  \n"+
                "from exchange  \n"+
                "where delete_flag=0 and build_id=? and status=?";
        preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setInt(1, buildId);
        preparedStatement.setString(2, "未审核");

        resultSet = preparedStatement.executeQuery();
        Integer count = null;
        if (resultSet.next()) {
            count = resultSet.getInt("exchange_all_count");
        }

        DBUtil.close(connection,preparedStatement,resultSet);


        return count;

    }
}
